package com.markus.code.exam.jd;

import java.util.Scanner;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/17 19:58
 * todo: 王子与公主
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            int T = scanner.nextInt();
            while(T != 0){
                int n = scanner.nextInt();
                int m = scanner.nextInt();
                boolean [][]matrix = new boolean[n][m];
                boolean [][]isVisited = new boolean[n][m];
                int wRow = 0;
                int wCol = 0;
                int gRow = 0;
                int gCol = 0;
                for (int i=0;i<matrix.length;i++){
                    String rowData = scanner.next();
                    char[] chars = rowData.toCharArray();
                    for (int j=0;j<matrix[i].length;j++){
                        if (chars[j] == '.'){
                            matrix[i][j] = true;
                        }else if (chars[j] == '#'){
                            matrix[i][j] = false;
                        }else if (chars[j] == 'E'){
                            matrix[i][j] = true;
                            wRow = i;
                            wCol = j;
                        }else if (chars[j] == 'S'){
                            matrix[i][j] = true;
                            gRow = i;
                            gCol = j;
                        }
                    }
                }
                System.out.println(process(matrix,matrix.length,matrix[0].length,wRow,wCol,gRow,gCol,isVisited)?"YES":"NO");
                T--;
            }
        }
    }
    private static boolean process(boolean[][] matrix,int rows,int cols,int startRow,int startCol,int endRow,int endCol,boolean[][] isVisited){
        if (startRow < 0 || startRow >= rows || startCol < 0 || startCol >= cols || !matrix[startRow][startCol] || isVisited[startRow][startCol]){
            return false;
        }
        if (startRow == endRow && startCol == endCol){
            return true;
        }
        isVisited[startRow][startCol] = true;
        boolean res =  process(matrix,rows,cols,startRow+1,startCol,endRow,endCol,isVisited)||
                process(matrix,rows,cols,startRow-1,startCol,endRow,endCol,isVisited)||
                process(matrix,rows,cols,startRow,startCol+1,endRow,endCol,isVisited)||
                process(matrix,rows,cols,startRow,startCol-1,endRow,endCol,isVisited);
        isVisited[startRow][startCol] = false;
        return res;
    }
}
